
$(document).ready(function() {


	$.ajax({
		type: "post",
		url: "index",
		async: true,
		dataType: 'json',
		success: function(data) {
			console.log(data)
			var resultJson = data.resultJson;
			//下次加载页数
			$('#paging').html('2');
			//登录成功
			if(data.userid >0) {	
				 $("#hedemax").html('<div class="am-header-left am-header-nav "><a href="index" class="iconfont pet_head_jt_ico"><img src="myAssets/img/首页.png"></a>  校园网</div><div class="am-header-right am-header-nav">发布<a href="###" class="iconfont pet_head_gd_ico" ><img src="myAssets/img/发布.png"></a></div>'); 	
			} 
			if(data.userid==-1){
			$("#hedemax").html('<div class="am-header-left am-header-nav "><a href="index" class="iconfont pet_head_jt_ico"><img src="myAssets/img/首页.png"></a>  校园网</div><div class="am-header-right am-header-nav">登录<a href="login" class="iconfont pet_head_gd_ico" ><img src="myAssets/img/登录.png"></a></div>'); 
			}
			
			var articlePath = 'myAssets//img//article//';// 文章文件路径
			var facePath = 'myAssets//img//face//';// 头像文件路径
			
			
			var list = data.pagerVo.lists;// 文章数组 
			for (var i = 0; i < list.length; i++) {

				var id = list[i].id;
				var type = list[i].type;// 类型
				var title = list[i].title;// 标题
				var content = list[i].content;// 内容
				var user = list[i].user;// 内容

				// 分享
				if (type == 'fenxiang') {
					type = '<div class="pet_list_tag pet_list_tag_zzs">分享</div>'
				}
				// 教学
				if (type == 'jiaoxue') {
					type = '<div class="pet_list_tag pet_list_tag_stj">教学</div>'
				}
				// 提问
				if (type == 'tiwen') {
					type = '<div class="pet_list_tag pet_list_tag_tiwen">提问</div>'
				}
				// 趣闻
				if (type == 'quwen') {
					type = '<div class="pet_list_tag pet_video_tag">校园趣闻</div>'
				}

				if (list[i].myFiles.length == 0) {
					$("#articel-List")
							.append(
									'<li class="am-g am-list-item-desced pet_list_one_block">  <div class="pet_list_one_info">  <div class="pet_list_one_info_l">      <div class="pet_list_one_info_ico"><a href="heUser?id='
											+ user.id
											+ '"><img src="'
											+ facePath
											+ user.myFile.name
											+ '" alt=""></a></div>     <div class="pet_list_one_info_name">'
											+ user.name
											+ '</div>   </div>      <div class="pet_list_one_info_r">'
											+ type
											+ '</div>  </div>  <div class=" am-list-main">  <h3 class="am-list-item-hd pet_list_one_bt"><a href="articleStudyOne?id='
											+ id
											+ '" class="">'
											+ title
											+ '</a></h3>  <div class="am-list-item-text pet_list_two_text">'
											+ content
											+ '</div>  </div>  </li>');
				}
				if (list[i].myFiles.length == 1
						|| list[i].myFiles.length == 2) {
					$("#articel-List")
							.append(
									'<li class="am-g am-list-item-desced am-list-item-thumbed am-list-item-thumb-right pet_list_one_block" style="/*border:none;*/"> <div class="pet_list_one_info"> <div class="pet_list_one_info_l">   <div class="pet_list_one_info_ico"><a href="heUser?id='
											+ user.id
											+ '"><img src="'
											+ facePath
											+ user.myFile.name
											+ '" alt=""></a></div> <div class="pet_list_one_info_name">'
											+ user.name
											+ '</div> </div>  <div class="pet_list_one_info_r">'
											+ type
											+ '</div> </div> <div class=" am-u-sm-8 am-list-main pet_list_one_nr"> <h3 class="am-list-item-hd pet_list_one_bt"><a href="articleStudyOne?id='
											+ id
											+ '" class="">'
											+ title
											+ '</a></h3> <div class="am-list-item-text pet_list_one_text01">'
											+ content
											+ '</div> </div>  <div class="am-u-sm-4 am-list-thumb">  <a href="articleStudyOne?id='
											+ id
											+ '" class="">  <img src="'
											+ articlePath
											+ list[i].myFiles[0].name
											+ '" class="pet_list_one_img" alt=""/> </a>  </div> </li>');
				}
				if (list[i].myFiles.length >= 3) {
					$("#articel-List")
							.append(
									' <li class="am-g am-list-item-desced pet_list_one_block"> <div class="pet_list_one_info"><div class="pet_list_one_info_l"> <div class="pet_list_one_info_ico"><a href="heUser?id='
											+ user.id
											+ '"><img src="'
											+ facePath
											+ user.myFile.name
											+ '" alt=""></a></div> <div class="pet_list_one_info_name">'
											+ user.name
											+ '</div> </div> <div class="pet_list_one_info_r">'
											+ type
											+ ' </div></div><div class=" am-list-main"> <h3 class="am-list-item-hd pet_list_one_bt"><a href="articleStudyOne?id='
											+ id
											+ '" class="">'
											+ title
											+ '</a></h3> <ul data-am-widget="gallery" class="am-gallery am-avg-sm-3 am-avg-md-3 am-avg-lg-3 am-gallery-default pet_list_one_list" ><li><div class="am-gallery-item"> <a href="articleStudyOne?id='
											+ id
											+ '" class=""> <img src="'
											+ articlePath
											+ list[i].myFiles[0].name
											+ '"  alt=""/> </a> </div> </li> <li> <div class="am-gallery-item"> <a href="articleStudyOne?id='
											+ id
											+ '" class=""> <img src="'
											+ articlePath
											+ list[i].myFiles[1].name
											+ '"  alt=""/> </a> </div> </li> <li><div class="am-gallery-item">  <a href="articleStudyOne?id='
											+ id
											+ '" class="">  <img src="'
											+ articlePath
											+ list[i].myFiles[2].name
											+ '"  alt=""/> </a> </div>  </li> </ul> <div class="am-list-item-text pet_list_two_text">'
											+ content
											+ '</div> </div> </li>');
				}

				$(document)
				.ready(
						function() {

							// 动态计算新闻列表文字样式
							auto_resize();
							$(window)
									.resize(
											function() {
												auto_resize();
											});
//							$('.am-list-thumb img').load(function() {
//							auto_resize();
//							});
							$(
									'.pet_article_like li:last-child')
									.css('border',
											'none');
							function auto_resize() {
								$(
										'.pet_list_one_nr')
										.height(
												$(
														'.pet_list_one_img')
														.height());
								// alert($('.pet_list_one_nr').height());
							}
							$('.pet_article_user')
									.on(
											'click',
											function() {
												if ($(
														'.pet_article_user_info_tab')
														.hasClass(
																'pet_article_user_info_tab_show')) {
													$(
															'.pet_article_user_info_tab')
															.removeClass(
																	'pet_article_user_info_tab_show')
															.addClass(
																	'pet_article_user_info_tab_cloes');
												} else {
													$(
															'.pet_article_user_info_tab')
															.removeClass(
																	'pet_article_user_info_tab_cloes')
															.addClass(
																	'pet_article_user_info_tab_show');
												}
											});

							$('.pet_head_gd_ico')
									.on(
											'click',
											function() {
												$(
														'.pet_more_list')
														.addClass(
																'pet_more_list_show');
											});
							$('.pet_more_close')
									.on(
											'click',
											function() {
												$(
														'.pet_more_list')
														.removeClass(
																'pet_more_list_show');
											});
						});
			
				$(function(){
				    // 动态计算新闻列表文字样式
				    auto_resize();
				    $(window).resize(function() {
				        auto_resize();
				    });
//				    $('.am-list-thumb img').load(function(){
//				        auto_resize();
//				    });

				    $('.am-list > li:last-child').css('border','none');
				    function auto_resize(){
				        $('.pet_list_one_nr').height($('.pet_list_one_img').height());

				    }
				        $('.pet_nav_gengduo').on('click',function(){
				            $('.pet_more_list').addClass('pet_more_list_show');
				       });
				        $('.pet_more_close').on('click',function(){
				            $('.pet_more_list').removeClass('pet_more_list_show');
				        });
				});
				
				
			}
			
			
		},
		error: function() {}
	});
})


// 获取url中的参数
function getQueryString(name) {
	var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i"); // 匹配目标参数
	var result = window.location.search.substr(1).match(reg); // 对querystring匹配目标参数
	if (result != null) {
		return decodeURIComponent(result[2]);
	} else {
		return null;
	}
}
//加载跟多按钮
$('#but-addList').click(function() {
	$('#but-addList').html('<i class="am-icon-spinner am-icon-spin"></i> 加载中...');
	//获取页面隐藏域的加载页数
	var paging=document.getElementById("paging").innerText;
	$.ajax({
		type : "post",
		async : true,
		url : "addPaging",
		data : {
			"curPage" : paging
		},
		dataType : 'json',
		success : function(data) {
			var paging2 = Number(paging)+1;
			$('#paging').html(paging2);	
			console.log('按钮已出发')
			console.log(paging2+'页')
			console.log(data.pagerVo.lists)
			$('#but-addList').html('加载跟多');
			
//便利加载的信息~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
			var articlePath = 'myAssets//img//article//';// 文章文件路径
			var facePath = 'myAssets//img//face//';// 头像文件路径

			var list = data.pagerVo.lists;// 文章数组 
			for (var i = 0; i < list.length; i++) {

				var id = list[i].id;
				var type = list[i].type;// 类型
				var title = list[i].title;// 标题
				var content = list[i].content;// 内容
				var user = list[i].user;// 内容

				// 分享
				if (type == 'fenxiang') {
					type = '<div class="pet_list_tag pet_list_tag_zzs">分享</div>'
				}
				// 教学
				if (type == 'jiaoxue') {
					type = '<div class="pet_list_tag pet_list_tag_stj">教学</div>'
				}
				// 提问
				if (type == 'tiwen') {
					type = '<div class="pet_list_tag pet_list_tag_tiwen">提问</div>'
				}
				// 趣闻
				if (type == 'quwen') {
					type = '<div class="pet_list_tag pet_video_tag">校园趣闻</div>'
				}

				if (list[i].myFiles.length == 0) {
					$("#articel-List")
							.append(
									'<li class="am-g am-list-item-desced pet_list_one_block">  <div class="pet_list_one_info">  <div class="pet_list_one_info_l">      <div class="pet_list_one_info_ico"><a href="heUser?id='
											+ user.id
											+ '"><img src="'
											+ facePath
											+ user.myFile.name
											+ '" alt=""></a></div>     <div class="pet_list_one_info_name">'
											+ user.name
											+ '</div>   </div>      <div class="pet_list_one_info_r">'
											+ type
											+ '</div>  </div>  <div class=" am-list-main">  <h3 class="am-list-item-hd pet_list_one_bt"><a href="articleStudyOne?id='
											+ id
											+ '" class="">'
											+ title
											+ '</a></h3>  <div class="am-list-item-text pet_list_two_text">'
											+ content
											+ '</div>  </div>  </li>');
				}
				if (list[i].myFiles.length == 1
						|| list[i].myFiles.length == 2) {
					$("#articel-List")
							.append(
									'<li class="am-g am-list-item-desced am-list-item-thumbed am-list-item-thumb-right pet_list_one_block" style="/*border:none;*/"> <div class="pet_list_one_info"> <div class="pet_list_one_info_l">   <div class="pet_list_one_info_ico"><a href="heUser?id='
											+ user.id
											+ '"><img src="'
											+ facePath
											+ user.myFile.name
											+ '" alt=""></a></div> <div class="pet_list_one_info_name">'
											+ user.name
											+ '</div> </div>  <div class="pet_list_one_info_r">'
											+ type
											+ '</div> </div> <div class=" am-u-sm-8 am-list-main pet_list_one_nr"> <h3 class="am-list-item-hd pet_list_one_bt"><a href="articleStudyOne?id='
											+ id
											+ '" class="">'
											+ title
											+ '</a></h3> <div class="am-list-item-text pet_list_one_text01">'
											+ content
											+ '</div> </div>  <div class="am-u-sm-4 am-list-thumb">  <a href="articleStudyOne?id='
											+ id
											+ '" class="">  <img src="'
											+ articlePath
											+ list[i].myFiles[0].name
											+ '" class="pet_list_one_img" alt=""/> </a>  </div> </li>');
				}
				if (list[i].myFiles.length >= 3) {
					$("#articel-List")
							.append(
									' <li class="am-g am-list-item-desced pet_list_one_block"> <div class="pet_list_one_info"><div class="pet_list_one_info_l"> <div class="pet_list_one_info_ico"><a href="heUser?id='
											+ user.id
											+ '"><img src="'
											+ facePath
											+ user.myFile.name
											+ '" alt=""></a></div> <div class="pet_list_one_info_name">'
											+ user.name
											+ '</div> </div> <div class="pet_list_one_info_r">'
											+ type
											+ ' </div></div><div class=" am-list-main"> <h3 class="am-list-item-hd pet_list_one_bt"><a href="articleStudyOne?id='
											+ id
											+ '" class="">'
											+ title
											+ '</a></h3> <ul data-am-widget="gallery" class="am-gallery am-avg-sm-3 am-avg-md-3 am-avg-lg-3 am-gallery-default pet_list_one_list" ><li><div class="am-gallery-item"> <a href="articleStudyOne?id='
											+ id
											+ '" class=""> <img src="'
											+ articlePath
											+ list[i].myFiles[0].name
											+ '"  alt=""/> </a> </div> </li> <li> <div class="am-gallery-item"> <a href="articleStudyOne?id='
											+ id
											+ '" class=""> <img src="'
											+ articlePath
											+ list[i].myFiles[1].name
											+ '"  alt=""/> </a> </div> </li> <li><div class="am-gallery-item">  <a href="articleStudyOne?id='
											+ id
											+ '" class="">  <img src="'
											+ articlePath
											+ list[i].myFiles[2].name
											+ '"  alt=""/> </a> </div>  </li> </ul> <div class="am-list-item-text pet_list_two_text">'
											+ content
											+ '</div> </div> </li>');
				}

				$(document)
				.ready(
						function() {

							// 动态计算新闻列表文字样式
							auto_resize();
							$(window)
									.resize(
											function() {
												auto_resize();
											});
//							$('.am-list-thumb img').load(function() {
//							auto_resize();
//							});
							$(
									'.pet_article_like li:last-child')
									.css('border',
											'none');
							function auto_resize() {
								$(
										'.pet_list_one_nr')
										.height(
												$(
														'.pet_list_one_img')
														.height());
								// alert($('.pet_list_one_nr').height());
							}
							$('.pet_article_user')
									.on(
											'click',
											function() {
												if ($(
														'.pet_article_user_info_tab')
														.hasClass(
																'pet_article_user_info_tab_show')) {
													$(
															'.pet_article_user_info_tab')
															.removeClass(
																	'pet_article_user_info_tab_show')
															.addClass(
																	'pet_article_user_info_tab_cloes');
												} else {
													$(
															'.pet_article_user_info_tab')
															.removeClass(
																	'pet_article_user_info_tab_cloes')
															.addClass(
																	'pet_article_user_info_tab_show');
												}
											});

							$('.pet_head_gd_ico')
									.on(
											'click',
											function() {
												$(
														'.pet_more_list')
														.addClass(
																'pet_more_list_show');
											});
							$('.pet_more_close')
									.on(
											'click',
											function() {
												$(
														'.pet_more_list')
														.removeClass(
																'pet_more_list_show');
											});
						});
			
				$(function(){
				    // 动态计算新闻列表文字样式
				    auto_resize();
				    $(window).resize(function() {
				        auto_resize();
				    });
//				    $('.am-list-thumb img').load(function(){
//				        auto_resize();
//				    });

				    $('.am-list > li:last-child').css('border','none');
				    function auto_resize(){
				        $('.pet_list_one_nr').height($('.pet_list_one_img').height());

				    }
				        $('.pet_nav_gengduo').on('click',function(){
				            $('.pet_more_list').addClass('pet_more_list_show');
				       });
				        $('.pet_more_close').on('click',function(){
				            $('.pet_more_list').removeClass('pet_more_list_show');
				        });
				});
				
				
			}
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
		},
		error : function() {
		}
	});

})

